package jgrit.options;

/**
 * 
 * @author Taylor Perkins
 *
 */
public class HexOption extends Option {
	
	private int maxLength;
	
	/* Constructor */
	public HexOption(String name, String group, String initialValue, int length)
	{
		super(name, group, initialValue);
		this.maxLength = length;
	}
	
	/* (non-Javadoc)
	 * @see jgrit.options.Option#validate()
	 */
	@Override
	public boolean validate() {
		char[] charValue = this.getValue().toCharArray();
		if (charValue.length > this.maxLength) {
			return false;
		}
		for (char val : charValue) {
			char upper = Character.toUpperCase(val);
			if ((upper < '0' || upper > '9') && (upper < 'A' || upper > 'F')) {
				return false;
			}
		}
		
		return true;
	}
	
	/* (non-Javadoc)
	 * @see jgrit.options.Option#isCharValid()
	 */
	@Override
	public boolean isCharValid(char c) {
		char upper = Character.toUpperCase(c);
		if ((upper < '0' || upper > '9') && (upper < 'A' || upper > 'F')) {
			return false;
		}
		
		return true;
	}
}
